package day4;

import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class GetAvg2 {
    public static void main(String[] args) {
        //方法1：利用i的值来判断是不是提前退出for
        Scanner in = new Scanner(System.in);
        double sum = 0;
        double s = 0;
        int i = 1;
        for (; i <= 5; i++) {
            System.out.println("input 成绩：");
            s = in.nextDouble();
            if (s < 0) {
                //System.out.println("输入错误，输入了负数！");
                break;
            }
            sum += s;
        }
        if(i>5){
            double avg = sum / 5;
            System.out.println("平均分是：" + avg);
        }else {
            System.out.println("输入错误，输入了负数！");
        }

    }
}
